# -*- coding: utf-8 -*-
"""
Created on Sun Sep 18 16:17:56 2022

@author: Runx
"""
import numpy as np
import matplotlib.pyplot as plt
import settings
import taichi as ti
import Stochastic_Rainfall_v3 as sr
import scipy.stats as st
import math
from scipy import stats
ti.init()
'''
a = ti.Vector.field(2, float, shape=(3,3))

@ti.kernel
def initialize_a():
    for i,j in a:
        a[i,j] = (i,j)

@ti.kernel
def test_a():
    tans = ti.Matrix([[0, 0.5],[0, ti.sqrt(3.0)/2]])
    for i,j in a:
        a[i,j] = tans @ a[i,j]


initialize_a()
print(a)
res1=a.to_numpy() 
test_a()
print(a)
res2=a.to_numpy()  
'''

_roi = settings.roi # a 2D grid with each lattice indexed
theta = 30/180 * math.pi # direction of envelope motivation, radian
roi = ti.Vector.field(2, int, shape=(10, 10))
roi.from_numpy(_roi)
T = ti.Vector.field(1000, float, shape=(10,10))
#roi_R = ti.Vector.field(2016,float,shape=(10, 10))
v_1, v_2 = (math.sin(theta), math.cos(theta)) #x,y方向上的速度，km/hr
Rot = ti.Matrix([[0, v_1], [0, v_2]])
print(roi)

@ti.kernel
def translate(x_offset:int, y_offset:int):
    '''
    Put the ROI to the right Position.
    '''
    for i,j in roi:
            roi[i,j] += (x_offset, y_offset)
@ti.kernel
def rotate():
    for i,j in roi:
        roi[i,j] = Rot @ roi[i,j]

rotate()
translate(400, 200)
print(roi)
for i in range(10, 20):
    loc = ti.Vector.field(2, int, shape=i)
    print("the", i, "th time")
    _pos = sr.loc_gen(i)
    loc.from_numpy(_pos.values)
    #test()

#ti.init()
#a = ti.field(int, shape=())
#b = ti.field(float, shape=())
#a[None]=1
#b[None] = a[None]
#print(a,b)
#roi = settings.roi
#test = ti.Vector.field(2, float, shape=(10,10))
#test.from_numpy(roi)
#print(test)